using System;
using System.Collections.Generic;
using System.Data;
using Orchard.ContentManagement.Drivers;
using Orchard.ContentManagement.MetaData;
using Orchard.ContentManagement.MetaData.Builders;
using Orchard.Core.Contents.Extensions;
using Orchard.Data.Migration;

namespace EMS.Calendar {
    public class Migrations : DataMigrationImpl {

        public int Create() {
			// Creating table CalendarPartRecord
			SchemaBuilder.CreateTable("CalendarPartRecord", table => table
				.ContentPartRecord()
				.Column("EventOccurrence", DbType.String)
				.Column("StartDate", DbType.DateTime)
				.Column("StartTime", DbType.DateTime)
				.Column("EndDate", DbType.DateTime)
				.Column("EndTime", DbType.DateTime)
				.Column("IsAllDayEvent", DbType.Boolean)
				.Column("Pattern", DbType.String)
				.Column("PeriodSpan", DbType.Int32)
				.Column("DayOfPeriod", DbType.Int32)
				.Column("DayInstance", DbType.String)
				.Column("DayNames", DbType.String)
				.Column("MonthName", DbType.String)
				.Column("RecurrenceEnd", DbType.String)
				.Column("NumberOccurrences", DbType.Int32)
			);

            ContentDefinitionManager.AlterPartDefinition("CalendarPart",
                part => part
                    .Attachable()
            );

            ContentDefinitionManager.AlterTypeDefinition("Calendar",
                cfg => cfg
                    .WithPart("CommonPart")
                    .WithPart("TitlePart")
                    .WithPart("AutoroutePart")
                    .WithPart("BodyPart")
                    .WithPart("CalendarPart")
                    .Creatable()
                    .Draftable()
            );

            return 1;
        }
    }
}